package com.shanglida.guide;

import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.shanglida.R;
import com.shanglida.activity.BaseActivity;
import com.shanglida.login.LoginActivity;
import com.shanglida.register.RegisterActivity;

/**
 * @author liu
 * @deprecated 主界面 登陆&注册%help类信息
 * @date 2014-03-05
 * @version 2.0
 * @copyright 广州尚礼达
 */
public class MainActivity extends BaseActivity implements OnClickListener {
	// 按钮 注册 &登陆
	private Button mregis, mlogin;
	// 定义控件
	public LinearLayout mLinearCtrlbar, mLinearAvatars;
	// 定义ImageView 测试mid1 mid2 以后可以扩展（可以生成事件）
	private ImageView mid1, mid2;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_welcome);
		initViews();
		initEvents();
		showWelcomeAnimation();
	}

	/*
	 * 加载启动动画效果 主界面 类似闪屏
	 * 
	 * @pamr 启动的时候 闪屏弹出liner界面
	 * 
	 * @date 2014-03-08
	 * 
	 * @author liu
	 */
	private void showWelcomeAnimation() {
		Animation animation = AnimationUtils.loadAnimation(MainActivity.this,
				R.anim.welcome_ctrlbar_slideup);
		animation.setAnimationListener(new AnimationListener() {

			@Override
			public void onAnimationStart(Animation animation) {
				mLinearAvatars.setVisibility(View.GONE);
			}

			@Override
			public void onAnimationRepeat(Animation animation) {

			}

			@Override
			public void onAnimationEnd(Animation animation) {
				new Handler().postDelayed(new Runnable() {

					@Override
					public void run() {
						mLinearAvatars.setVisibility(View.VISIBLE);
					}
				}, 800);
			}
		});
		mLinearCtrlbar.startAnimation(animation);
	}

	/*
	 * 初始化
	 */
	@Override
	protected void initViews() {
		mregis = (Button) findViewById(R.id.welcome_btn_register);
		mlogin = (Button) findViewById(R.id.welcome_btn_login);
		mLinearCtrlbar = (LinearLayout) findViewById(R.id.welcome_linear_ctrlbar);
		mLinearAvatars = (LinearLayout) findViewById(R.id.welcome_linear_avatars);
		mid1 = (ImageView) findViewById(R.id.adv_ned1);
		mid2 = (ImageView) findViewById(R.id.adv_ned2);
	}

	@Override
	protected void initEvents() {
		mregis.setOnClickListener(this);
		mlogin.setOnClickListener(this);
		mid1.setOnClickListener(this);
		mid2.setOnClickListener(this);

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		// 注册
		case R.id.welcome_btn_register:
			startActivity(RegisterActivity.class);
			break;
		// 进入登陆界面
		case R.id.welcome_btn_login:
			startActivity(LoginActivity.class);

			break;
		case R.id.adv_ned1:
			showCustomToast("广告位1");
			break;
		case R.id.adv_ned2:
			showCustomToast("广告位2");
			break;
		default:
			break;
		}
	}

	// /**
	// *
	// */
	// @Override
	// public void onBackPressed() {
	// showAlertDialog("提示", "您真的要退出?", android.R.drawable.ic_dialog_info,
	// "确定", new DialogInterface.OnClickListener() {
	//
	// @Override
	// public void onClick(DialogInterface dialog, int which) {
	// dialog.dismiss();
	// // 默认关闭界面
	// defaultFinish();
	// }
	// }, "取消", new DialogInterface.OnClickListener() {
	//
	// @Override
	// public void onClick(DialogInterface dialog, int which) {
	// dialog.cancel();
	// }
	// });
	// }

}
